package com.yoga.service.impl;

import com.yoga.entity.YogaCoachprivate;
import com.yoga.entity.YogaPrivaterequest;
import com.yoga.entity.YogaPrivaterequestExample;
import com.yoga.mapper.YogaCoachprivateDao;
import com.yoga.mapper.YogaPrivaterequestDao;
import com.yoga.service.CoachprivateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class CoachprivateServiceImpl implements CoachprivateService {
    @Autowired
    private YogaCoachprivateDao yogaCoachprivateDao;
    @Autowired
    private YogaPrivaterequestDao yogaPrivaterequestDao;
    @Override
    public List<YogaCoachprivate> getAll() {
        return yogaCoachprivateDao.selectByExample(null);
    }

    @Override
    public YogaCoachprivate getBycpid(Integer cpid) {
        YogaCoachprivate yogaCoachprivate = yogaCoachprivateDao.selectByPrimaryKey(cpid);
        return yogaCoachprivate;
    }

    @Override
    public List<YogaPrivaterequest> coachByPrivate(Integer coachuid) {
        List<YogaPrivaterequest> yogaPrivaterequests = yogaPrivaterequestDao.coachByPrivate(coachuid);
        return yogaPrivaterequests;
    }

    @Override
    public List<YogaPrivaterequest> userByPrivate(String uid) {
        List<YogaPrivaterequest> yogaPrivaterequests = yogaPrivaterequestDao.userByPrivate(uid);
        return yogaPrivaterequests;
    }

    @Override
    public List<String> getByPrivatetime(Integer uid, Integer month, Integer day) {
        YogaPrivaterequestExample example = new YogaPrivaterequestExample();
        example.createCriteria().andUidEqualTo(String.valueOf(uid));
        List<YogaPrivaterequest> yogaPrivaterequests = yogaPrivaterequestDao.selectByExample(example);
        List<String> list  = new ArrayList<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        for (YogaPrivaterequest request :yogaPrivaterequests) {
            System.out.println(dateFormat.format(date));
            System.out.println(dateFormat.format(request.getRequesttime()));
            if (dateFormat.format(request.getRequesttime()).equals(dateFormat.format(date))){
                String[] split = request.getPrivatetime().split(",");
                for (String str:split){
                    list.add(str);
                }
            }
        }
        return list;
    }
}
